import socket
import threading
import time

import robomaster.robot

udp_client3 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_client3.bind(('192.168.10.4', 8889))

# udp_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# udp_client.bind(('192.168.10.4', 10000))

command = b'command'
udp_client3.sendto(command, ('192.168.10.1', 8889))

robomaster.config.LOCAL_IP_STR = "192.168.10.4"
tl_drone = robomaster.robot.Drone()
tl_drone.initialize()

# 请注意，原始的 socket 已经无法使用，因为它的文件描述符已经被复制到 gevent_sock 中
tl_flight: robomaster.flight.Flight = tl_drone.flight

def fly():
    tl_flight.takeoff().wait_for_completed()
    while True:
        tl_flight.go(0, 0, 80, mid='m3').wait_for_completed()
        time.sleep(5)


def log():
    while True:
        data = tl_drone._status_sub.all_info()
        print(data)
        # string=data.encode()
        # udp_client.sendto(string,('192.168.10.2', 10001))
        time.sleep(10)

t1 = threading.Thread(target=fly)
t2 = threading.Thread(target=log)

t1.start()
t2.start()
